package com.xiaoshuidi.cloud.module.member.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoshuidi.cloud.module.member.controller.admin.questionnaireinfo.vo.QuestionVO;
import com.xiaoshuidi.cloud.module.member.controller.admin.questionnaireinfo.vo.QuestionnaireExcelCountVO;
import com.xiaoshuidi.cloud.module.member.mapper.questionnaireinfo.MemberQuestionMapper;
import com.xiaoshuidi.cloud.module.member.pojo.questionnaireinfo.MemberQuestion;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository
@RequiredArgsConstructor
@Slf4j
public class MemberQuestionRepository extends ServiceImpl<MemberQuestionMapper, MemberQuestion> {
    private final MemberQuestionMapper mapper;


    public List<MemberQuestion> getQuestionsByQuestionnaireId(Long id) {
        LambdaQueryWrapper<MemberQuestion> wrapper = new LambdaQueryWrapper<MemberQuestion>().eq(MemberQuestion::getQuestionnaireId, id);
        return mapper.selectList(wrapper);
    }

    public List<QuestionVO> getQuestionList(Long questionnaireId) {
        return mapper.getQuestionList(questionnaireId);
    }

    public List<QuestionnaireExcelCountVO> getgetQuestionnaireData(Long questionnaireId) {
        return mapper.getgetQuestionnaireData(questionnaireId);
    }

    public Boolean removeBatchByQuestionnaireId(Long questionnaireId) {
        Map<String, Object> map = new HashMap<>();
        map.put("questionnaire_id", questionnaireId);
        mapper.deleteByMap(map);
        return true;
    }
}
